//到货通知单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var manual_id=thisform.find('input[name=manual_id]').val();
		var goods_no=thisform.find('input[name=goods_no]').val();
		var goods_name=thisform.find('input[name=goods_name]').val();
		var cloud_depot_status=thisform.find('.cloud_depot_status').combobox('getValue');
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var time_cate=thisform.find('input[name=time_cate]').val();
		// console.log(inbound_status);
		// return false;
		$('#Datagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#Datagrid').datagrid({ 
			queryParams:{
				order_no:order_no,
				manual_id:manual_id,
				goods_no:goods_no,
				goods_name:goods_name,
				status:0,//未审核
				cloud_depot_status:cloud_depot_status,
				start_time:start_time,
				end_time:end_time,
				time_cate:time_cate
			}
		});
	})
	$('#Datagrid').datagrid({
		//url:getarrivalUrl+"?randnum="+Math.floor(Math.random()*1000000),
		queryParams:{
			status:0//未审核
		},
		url:getarrivalUrl,
		title:'到货通知单（仓库管理人员确认仓库有地方存货，仓库容量不够则审核不通过，审核通过则推到确认到货菜单）',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'order_no',title:'单号',sortable:true},
		{field:'batch_no',title:'批次号',sortable:true},
		{field:'manual_id',title:'账册编号'},
		{field:'goods_no',title:'商品编码'},
		{field:'goods_name',title:'商品名称'},
		{field:'declare_amount',title:'预计到货数量',sortable:true},
		{field:'price',title:'单价'},
		// {field:'bound_cate_code',width:'200px',title:'入库类别',sortable:true,
				// formatter:function(value,row,index){
					// htmlobj=$.ajax({type:'post',url:getBoundCateNameUrl,data:{code:value},async:false});//ajax动态获取出入库类别的名称
					// var info=eval('('+htmlobj.responseText+')');
					// return info.name;
				// }
		// },
		{field:'expected_time',title:'预计到货时间',sortable:true},
		{field:'add_time',title:'接收时间',sortable:true},
		{field:'examine_time',title:'审核时间',sortable:true},
		{field:'status',title:'审核状态',sortable:true}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
	});
});
authUserObj={
	add:function(url){
		$('#authUserAddForm').form('submit',{
			url:url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	var result=eval('('+result+')');
                if(!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#authUserAddDialog').dialog('close');  
                    });
                }else{
                    $('#authUserAddDialog').dialog('close');       
                    $('#authUserDatagrid').datagrid('reload'); 
                }
            },
		});
	},
	save:function(url){
		$('#authUserEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	 var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#authUserEditDialog').dialog('close');
                    });
                }else{
                    $('#authUserEditDialog').dialog('close');      
                    $('#authUserDatagrid').datagrid('reload');    
                }
            }
        });
	},
	showAll:function(){
		$('#Datagrid').datagrid({ queryParams:'status:0'});
	},
	examineBar:function(value){
		var authUserRow=$('#Datagrid').datagrid('getSelections');
		if(value==1){
			var text='确定审核通过吗！';
		}
		if(value==2){
			var text='确定审核不通过吗！';
		}
        if (authUserRow.length>0){
        	$.messager.confirm('审核提示',text,function(r){
                if (r){
                	var ids=[];
                	for(var i=0;i<authUserRow.length;i++){
                		ids.push(authUserRow[i].id);
                	}
                	var id=ids.join(',');
                    $.post(examineUrl,{id:id,value:value},function(result){
                        if (result.status){
                            $('#Datagrid').datagrid('reload');
                        }else{
                            $.messager.alert('错误提示',result.message,'error');
                        }
                    },'json').error(function(data){
                    	var info=eval('('+data.responseText+')');
						$.messager.confirm('错误提示',info.message,function(r){
							//$('#authAccessSetDialog').dialog('close');
						});
                    });	
                }
        	});
		}else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	}
}